package com.wenjie.original.entity;


import com.mybatisflex.annotation.EnumValue;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import com.mybatisflex.core.keygen.KeyGenerators;
import com.wenjie.common.enumHandler.IEnum;
import com.wenjie.original.entity.common.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.Arrays;

@Data
@Table("sys_menu")
@ApiModel("菜单权限表 ")
public class SysMenu extends BaseEntity {

    @Id(keyType = KeyType.Generator, value = KeyGenerators.snowFlakeId)
    @ApiModelProperty("菜单ID")
    private Long sysMenuId;

    @ApiModelProperty("父菜单ID")
    private Long parentId;

    @ApiModelProperty("显示顺序")
    private Long menuOrder;

    @ApiModelProperty("路由地址")
    private String menuPath;

    @ApiModelProperty("菜单标题")
    private String menuTitle;

    @ApiModelProperty("组件路径")
    private String menuComponent;

    @ApiModelProperty("菜单图标")
    private String menuIcon;

    @ApiModelProperty("类型（M目录 C菜单 F按钮）")
    private MENU_TYPE menuType;

    @ApiModelProperty("是否缓存（0缓存 1不缓存）")
    private Boolean isCache;

    @ApiModelProperty("显示状态（0显示 1隐藏）")
    private Boolean visible;

    @ApiModelProperty("权限字符串")
    private String perms;

    @ApiModelProperty("路由参数")
    private String other;

    @Getter
    @AllArgsConstructor
    public enum MENU_TYPE implements IEnum<String> {
        argM("M", "目录"),
        argC("C", "菜单"),
        argF("F", "按钮");

        @EnumValue
        private String code;
        private String message;

        /**
         * @Description 通过code进行查询枚举值
         * @author wenjie
         * @date 2024/5/30 15:21
         */
        public MENU_TYPE getBycode(String code) {
            return Arrays.stream(MENU_TYPE.values()).filter(s -> s.getCode().equals(code)).findFirst().orElse(null);
        }
    }


}
